package com.dgj.sigar.gathers;

import org.hyperic.sigar.Cpu;
import org.hyperic.sigar.CpuInfo;
import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.nutz.lang.util.NutMap;

/**
 * 收集的cpu信息
 * 
 * @author wkipy
 *
 */
public class CPUGather {

	private int count;

	private CpuInfo[] infos;

	private Cpu[] cpus;

	private CpuPerc[] percs;

	private NutMap total = NutMap.NEW();

	public int getCount() {
		return count;
	}

	public CpuInfo[] getInfos() {
		return infos;
	}

	public Cpu[] getCpus() {
		return cpus;
	}

	public CpuPerc[] getPercs() {
		return percs;
	}

	public CPUGather() {
		super();
	}

	public CPUGather(Sigar sigar) throws SigarException {
		init(sigar);
	}

	public static CPUGather init(Sigar sigar) {
		CPUGather gather = new CPUGather();
		try {
			gather.cpus = sigar.getCpuList();
			gather.count = gather.cpus.length;
			gather.infos = sigar.getCpuInfoList();
			gather.percs = sigar.getCpuPercList();
			gather.total.put("cpu", sigar.getCpu());
			gather.total.put("cpuPerc", sigar.getCpuPerc());
		} catch (SigarException e) {
			e.printStackTrace();
		}
		return gather;
	}
}
